<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>11函数柯里化</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
  <!-- 生产环境中不建议使用 -->
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js"></script>

  <script type="text/babel">
    class Life extends React.Component {
      state = {
        count: 0,
      }

      hadleDeath = () => {
        ReactDOM.unmountComponentAtNode(document.getElementById('app'))
      }

      add = () => {
        const { count } = this.state
        this.setState({ count: count + 1 })
      }

      // 钩子函数-componentWillMount-组件即将挂载
      componentWillMount() {
        console.log('componentWillMount')
      }

      // 钩子函数-componentDidMount-组件挂载完毕
      componentDidMount() {
        console.log('componentMounted')
      }

      // 钩子函数-componentWillUnmount-组件即将销毁
      componentWillUnmount() {
        console.log('componentWillUnmount')
      }

      // 钩子函数-shoulComponentUpdate-是否允许更新，默认是true
      shouldComponentUpdate() {
        console.log('shoulComponentUpdate')
        return true
      }

      // 钩子函数-componentWillUpdate-组件即将更新
      componentWillUpdate() {
        console.log('componentWillUpdate')
      }

      // 钩子函数-componentDidUpdate-组件更新完毕
      componentDidUpdate() {
        console.log('componentDidUpdate')
      }

      // 钩子函数-componentDidUpdate-组件更新完毕
      componentDidUpdate() {
        console.log('componentDidUpdate')
      }

      // 钩子函数-render
      render() {
        return (
          <div>
           <p>数值：{this.state.count}</p>
           <p><button onClick={this.add}>+1</button></p>
           <p><button onClick={this.hadleDeath}>销毁组件</button></p>
          </div>
        )
      }
    }
    ReactDOM.render(<Life />, document.getElementById('app'))
  </script>
</body>
</html>